package com.api.hg.action;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.hg.BaseUtle;
import com.api.hg.DoorUtil;
import com.api.hg.model.Uf_cxjlb;
import com.api.hg.model.Uf_newxz_rkppjl;
import com.api.hg.model.uf_xzqr;
import com.api.hg.service.*;
import com.api.hg.util.XzUtil;
import com.api.sw.duban.util.BaseUtil;
import com.api.sw.duban.util.DubUtil;
import com.api.sw.duban.util.LogTool;
import com.api.sw.duban.util.SqlUtil;
import com.cloudstore.eccom.constant.WeaBoolAttr;
import com.cloudstore.eccom.pc.table.WeaTable;
import com.cloudstore.eccom.pc.table.WeaTableColumn;
import com.cloudstore.eccom.pc.table.WeaTableType;
import com.cloudstore.eccom.result.WeaResultMsg;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.PageIdConst;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;

//viewtype=0&lx=0
public class assetAction {
    private final static LogTool log = new LogTool("/log/assetlog/luolf/assetAction",false);
    public JSONObject getSubTree(HttpServletRequest var1, HttpServletResponse var2){
        JSONArray tree=new JSONArray();

        JSONObject data=new JSONObject();
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            int userid= user.getUID();

            String subid= Util.null2String(var1.getParameter("subid")) ;//35//分部 ID
            String depid= Util.null2String(var1.getParameter("depid")) ;//部门ID
            String viewtype= Util.null2String(var1.getParameter("viewtype")) ;// 0新建  1编辑
            String lx= Util.null2String(var1.getParameter("lx")) ;// 0：分部  1：部门
            String billid= Util.null2String(var1.getParameter("billid")) ;//数据ID
            log.writeLog("getSubTree subid-->"+subid);
            log.writeLog("getSubTree depid-->"+depid);
            log.writeLog("getSubTree viewtype-->"+viewtype);
            log.writeLog("getSubTree lx-->"+lx);
            log.writeLog("getSubTree billid-->"+billid);
            if("".equals(billid)){
                viewtype="0";
            }
            BaseUtle BaseUtle=new BaseUtle();


            //需要判断 是否 有 权限  第一 是 角色  第二是 矩阵
            if(!BaseUtle.ckeckRole(userid+"",BaseUtle.sysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.subsysadmin)){
                return data;
            }


            if("0".equals(lx)){//分部
                //获取当前的权限分部 subid

                if(BaseUtle.ckeckRole( userid+"",BaseUtle.sysadmin+"")){
                    subid=BaseUtle.defindsub;
                }else if(BaseUtle.ckeckRole( userid+"",BaseUtle.zssysadmin+"")){
                    subid=BaseUtle.zshgsub+"";
                }else{
                    subid=BaseUtle.getSubidByMax(userid+"","0");
                    if("".equals(subid)){
                        return data;
                    }
                }
                tree= BaseUtle.getSubTree(subid);//分部 部门 数节点
                data.put("tree",tree);
                //获取数据
                if("1".equals(viewtype)){//编辑获取数据
                    BaseUtle.getSubModelData(billid,data);
                }
            }else if("1".equals(lx)){//部门
                //判断是和否是 科室部门资产管理员
                if(!BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)){
                    return data;
                }
                //获取分部矩阵 人员对应的部门
                if(BaseUtle.ckeckRole(userid+"",BaseUtle.sysadmin+"")){
                    subid=BaseUtle.defindsub;
                    //递归分部下面的部门 getDepTree
                    tree= BaseUtle.getSubTreeDispaly(subid);//部门 数节点
                    log.writeLog("sys tre"+tree.toJSONString());
                    data.put("tree",tree);
                }else{
                    subid=BaseUtle.getSubidByMax(userid+"","0");
                    if("".equals(subid)){
                        return data;
                    }
                    //递归分部下面的部门 getDepTree
                    tree= BaseUtle.getDepTree(subid);//部门 数节点
                    data.put("tree",tree);
                }


                //获取数据
                if("1".equals(viewtype)){//编辑获取数据
                    BaseUtle.getDepModelData(billid,data);
                }
            }



        }catch(Exception e){
            log.writeLog(e.getMessage());
        }
        return data;

    }

    /**
     * 校验 部们 科室 是否已经存在数据
     * @param json
     * @return
     */
    public String CkeckUpdModelRole(JSONObject json){
        log.writeLog("CkeckUpdModelRole-->"+json.toJSONString());
        String mess="";
        String billid=Util.null2String(json.getString("billid"));//建模数据ID
        String subid=Util.null2String(json.getString("subid"));//分部ID
        String depid=Util.null2String(json.getString("depid"));//部门ID
        String userid=Util.null2String(json.getString("userid"));//人员ID
        String lx=Util.null2String(json.getString("lx"));//权限类型  0:分部 1：部门
        if("".equals(billid)){//新建
            String sql="";
            if("0".equals(lx)){
                sql="";
            }
        }
        return "";
    }
    /*
        数据写入建模以及 角色
        private String modedatacreater="1";//创建人
        @Field(dbFiledName="")
        private String modedatacreatedate="";//创建日期
        @Field(dbFiledName="")
        private String formmodeid="25";//模型ID 默认值 本地6
        @Field(dbFiledName="")
        private String modedatacreatertype="0";//创建类型
        @Field(dbFiledName="")
        private String modedatacreatetime="";//创建时间
        @Field(dbFiledName="")
        private String modeuuid="";//UUID
     */
    public String UpdModelRole(JSONObject json){
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentdate=sim.format(new Date()).split(" ")[0];
        String currenttime=sim.format(new Date()).split(" ")[1];
        String mess="";
        if(json==null||json.size()<=0){
            return "";
        }
        List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
        RecordSet re=new RecordSet();
        RecordSet re1=new RecordSet();
        RecordSet re2=new RecordSet();
        log.writeLog("UpdModelRole-->"+json.toJSONString());

        String billid=Util.null2String(json.getString("billid"));//建模数据ID
        String subid=Util.null2String(json.getString("subid"));//分部ID
        String depid=Util.null2String(json.getString("depid"));//部门ID
        String userid=Util.null2String(json.getString("userid"));//人员ID
        if("".equals(subid)&&"".equals(depid)&&"".equals(userid)){
            return "参数异常!";
        }
        String curruserid=Util.null2String(json.getString("curruserid"));//当前人员ID
        String lx=Util.null2String(json.getString("lx"));//权限类型  0:分部 1：部门
        String js="";//用来更新的角色
        if("0".equals(lx)){
            if((BaseUtle.zshgsub+"").equals(subid)){
                js=BaseUtle.zssysadmin+"";
            }else{
                js=BaseUtle.subsysadmin+"";
            }
        }else{
            js=BaseUtle.bmsysadmin+"";
        }

        if("0".equals(lx)){//分部
            mess=checkSubOther(subid,userid);
            if(!"".equals(mess)){
                return mess;
            }
            Map<String,Object> modelmap=null;//modelmap=new HashMap<String,Object>();
            // 建模
            String demosql="select 1 from "+BaseUtle.subtable+" where bmmc="+subid;
            re.execute("select 1 from "+BaseUtle.subtable+" where bmmc="+subid);

            if(!re.next()){

                //修改
                modelmap=new HashMap<String,Object>();
                Object[] obj=new Object[8];
                modelmap.put("sql","insert into "+BaseUtle.subtable+"(bmmc,zcgly,modedatacreater,modedatacreatedate,formmodeid,modedatacreatertype,modedatacreatetime,modeuuid)values(?,?,?,?,?,?,?,?)");
                obj[0]=subid;
                obj[1]=userid;
                obj[2]=curruserid;
                obj[3]=currentdate;
                obj[4]=BaseUtle.submodeid;
                obj[5]=0;
                obj[6]=currenttime;
                obj[7]=UUID.randomUUID().toString();;
                modelmap.put("params",obj);
                list.add(modelmap);
            }else{
                if("".equals(billid)){
                    return "已经维护了资产管理员不可重复创建";
                }
                //isnert
                modelmap=new HashMap<String,Object>();
                Object[] obj=new Object[1];
                modelmap.put("sql","update "+BaseUtle.subtable+" set zcgly=? where bmmc='"+subid+"' ");
                obj[0]=userid;
                modelmap.put("params",obj);
                list.add(modelmap);
            }
            //角色 （中山海关特殊处理）
            String oldSubMaxHrm = Util.null2String(BaseUtle.getHrmidByMax(subid, "0")).trim();
            String diffenthrm=getnotCludeStr(userid,oldSubMaxHrm);//获取前以前不一样的人员信息
            //删除分析
            if(!"".equals(diffenthrm)&&!js.equals(BaseUtle.zssysadmin)) {
                String[] diffenthrms = diffenthrm.split(",");
                for (String userdemo : diffenthrms) {
                    userdemo = Util.null2String(userdemo).trim();
                    if ("".equals(userdemo)) {
                        continue;
                    }
                    boolean isVali = false;
                    isVali = BaseUtle.checkSubMaxibyHrm(userdemo, subid);//判断是和否存在
                    if (!isVali) {//不存在其他的矩阵
                        modelmap = new HashMap<String, Object>();
                        Object[] obj = new Object[2];
                        modelmap.put("sql", "delete from hrmrolemembers where roleid=? and  resourceid=?");
                        obj[0] = js;
                        obj[1] = userdemo;
                        modelmap.put("params", obj);
                        list.add(modelmap);
                    }
                }
            }
            String[] userids = userid.split(",");
            if(!js.equals(BaseUtle.zssysadmin)){
                for (String userdemo : userids) {
                    userdemo = Util.null2String(userdemo).trim();
                    if ("".equals(userdemo)) {
                        continue;
                    }
                    boolean isVali = false;
                    isVali = BaseUtle.checkSubMaxibyHrm(userdemo, subid);//判断是和否存在
                    re1.execute("select 1 from hrmrolemembers where roleid in (" + js + ") and resourceid in (" + userdemo + ")");
                    if (re1.next()) {


                    } else {//新曾
                        modelmap = new HashMap<String, Object>();
                        Object[] obj = new Object[5];
                        modelmap.put("sql", "insert into hrmrolemembers(resourcetype,roleid,resourceid,rolelevel,uuid)values(?,?,?,?,?)");
                        obj[0] = 1;
                        obj[1] = js;
                        obj[2] = userdemo;
                        obj[3] = 2;
                        obj[4] = UUID.randomUUID().toString();
                        modelmap.put("params", obj);
                        list.add(modelmap);
                    }


                }
            }else{
                modelmap = new HashMap<String, Object>();
                Object[] obj = new Object[1];
                modelmap.put("sql", "delete from hrmrolemembers where roleid=? ");
                obj[0] = js;
                modelmap.put("params", obj);
                list.add(modelmap);
                for (String userdemo : userids) {
                    userdemo = Util.null2String(userdemo).trim();
                    if ("".equals(userdemo)) {
                        continue;
                    }
                    modelmap = new HashMap<String, Object>();
                    Object[] obj1 = new Object[5];
                    modelmap.put("sql", "insert into hrmrolemembers(resourcetype,roleid,resourceid,rolelevel,uuid)values(?,?,?,?,?)");
                    obj1[0] = 1;
                    obj1[1] = js;
                    obj1[2] = userdemo;
                    obj1[3] = 2;
                    obj1[4] = UUID.randomUUID().toString();
                    modelmap.put("params", obj);
                    list.add(modelmap);
                }
            }




            //矩阵
            re2.execute("select * from HrmSubcompanyDefined where subcomid="+subid);
            if(!re2.next()){
                modelmap=new HashMap<String,Object>();
                Object[] obj=new Object[2];
                modelmap.put("sql","insert into HrmSubcompanyDefined(subcomid,"+BaseUtle.subdefined+")values(?,?)");
                obj[0]=subid;
                obj[1]=userid;
                modelmap.put("params",obj);
                list.add(modelmap);
            }else{
                modelmap=new HashMap<String,Object>();
                Object[] obj=new Object[1];
                modelmap.put("sql","update  HrmSubcompanyDefined set "+BaseUtle.subdefined+"=? where subcomid="+subid);
                obj[0]=userid;
                modelmap.put("params",obj);
                list.add(modelmap);
            }

        }
        if("1".equals(lx)){//部门
            Map<String,Object> modelmap=null;//modelmap=new HashMap<String,Object>();
            // 建模
            re.execute("select 1 from "+BaseUtle.bmbtable+" where bmmc="+depid);
            if(!re.next()){

                //修改
                modelmap=new HashMap<String,Object>();
                Object[] obj=new Object[9];
                modelmap.put("sql","insert into "+BaseUtle.bmbtable+"(bmmc,zcgly,modedatacreater,modedatacreatedate,formmodeid,modedatacreatertype,modedatacreatetime,modeuuid,szbm)values(?,?,?,?,?,?,?,?,?)");
                obj[0]=depid;
                obj[1]=userid;
                obj[2]=curruserid;
                obj[3]=currentdate;
                obj[4]=BaseUtle.depmodeid;
                obj[5]=0;
                obj[6]=currenttime;
                obj[7]=UUID.randomUUID().toString();
                //给科室管理员授权表里的所在部门增加内容 huangwm
                obj[8]=BaseUtle.getSubidBydepid(depid);
                modelmap.put("params",obj);
                list.add(modelmap);
            }else{
                if("".equals(billid)){
                    return "已经维护了资产管理员不可重复创建";
                }
                //isnert
                modelmap=new HashMap<String,Object>();
                Object[] obj=new Object[1];
                modelmap.put("sql","update "+BaseUtle.bmbtable+" set zcgly=? where bmmc='"+depid+"' ");
                obj[0]=userid;
                modelmap.put("params",obj);
                list.add(modelmap);
            }
            //角色 （中山海关特殊处理）
            String oldDepMaxHrm = Util.null2String(BaseUtle.getHrmidByMax(depid, "1")).trim();
            String diffenthrm=getnotCludeStr(userid,oldDepMaxHrm);//获取前以前不一样的人员信息

            //删除分析
            if(!"".equals(diffenthrm)) {
                String[] diffenthrms = diffenthrm.split(",");
                for (String userdemo : diffenthrms) {
                    userdemo = Util.null2String(userdemo).trim();
                    if ("".equals(userdemo)) {
                        continue;
                    }
                    boolean isVali = false;
                    isVali = BaseUtle.checkDepMaxibyHrm(userdemo, depid);//判断是和否存在
                    if (!isVali) {//不存在其他的矩阵
                        modelmap = new HashMap<String, Object>();
                        Object[] obj = new Object[2];
                        modelmap.put("sql", "delete from hrmrolemembers where roleid=? and  resourceid=?");
                        obj[0] = js;
                        obj[1] = userdemo;
                        modelmap.put("params", obj);
                        list.add(modelmap);
                    }
                }
            }

            String[] userids = userid.split(",");
            for (String userdemo : userids) {
                userdemo = Util.null2String(userdemo).trim();
                if ("".equals(userdemo)) {
                    continue;
                }
                boolean isVali = false;
                isVali = BaseUtle.checkDepMaxibyHrm(userdemo, subid);//判断是和否存在
                re1.execute("select 1 from hrmrolemembers where roleid in (" + js + ") and resourceid in (" + userdemo + ")");
                if (re1.next()) {

//                        //删除
//                        if (!isVali) {//不存在其他的矩阵
//                            if (("," + oldDepMaxHrm + ",").indexOf(("," + userdemo + ",")) < 0) {//不存在原有的矩阵
//                                modelmap = new HashMap<String, Object>();
//                                Object[] obj = new Object[2];
//                                modelmap.put("sql", "delete from hrmrolemembers where roleid=? and  resourceid=?");
//                                obj[0] = js;
//                                obj[1] = userdemo;
//                                modelmap.put("params", obj);
//                                list.add(modelmap);
//                            }
//                        } else {//存在  不考虑删除
//
//                        }
                } else {//新曾
                    modelmap = new HashMap<String, Object>();
                    Object[] obj = new Object[5];
                    modelmap.put("sql", "insert into hrmrolemembers(resourcetype,roleid,resourceid,rolelevel,uuid)values(?,?,?,?,?)");
                    obj[0] = 1;
                    obj[1] = js;
                    obj[2] = userdemo;
                    obj[3] = 2;
                    obj[4] = UUID.randomUUID().toString();
                    modelmap.put("params", obj);
                    list.add(modelmap);
                }


            }

            //矩阵
            re2.execute("select * from HrmDepartmentDefined where deptid="+depid);
            if(!re2.next()){
                modelmap=new HashMap<String,Object>();
                Object[] obj=new Object[2];
                modelmap.put("sql","insert into HrmDepartmentDefined(deptid,"+BaseUtle.depefined+")values(?,?)");
                obj[0]=depid;
                obj[1]=userid;
                modelmap.put("params",obj);
                list.add(modelmap);
            }else{
                modelmap=new HashMap<String,Object>();
                Object[] obj=new Object[1];
                modelmap.put("sql","update  HrmDepartmentDefined set "+BaseUtle.depefined+"=? where deptid="+depid);
                obj[0]=userid;
                modelmap.put("params",obj);
                list.add(modelmap);
            }
        }
        if(list!=null&&list.size()>0){
            log.writeLog(list.toString());
            boolean flag=SqlUtil.executeUpdateListTran("local",list);
            if(!flag){
                mess="更新失败!";
            }else{
                try{
                    //同步部门数据到矩阵
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            weaver.matrix.MatrixUtil.sysDepartmentData();
                            weaver.matrix.MatrixUtil.sysSubcompayData();
                            //重构资产
                            if("0".equals(lx)) {//分部
                                restModeSW(lx,subid);
                                restModeGB(lx,subid);
                            }
                            if("1".equals(lx)) {//部门
                                restModeSW(lx,depid);
                            }
                        }
                    }).start();

                }catch (Exception e) {

                }
                //huangwm 增加用于管理员授权时重构数据权限
                ModeRightInfo mri=new ModeRightInfo();
                //权限重构
                if("0".equals(lx)){//分部
                    re.execute("select * from "+BaseUtle.subtable+" where bmmc="+subid);
                    if(re.next()){
                        int dataid=Util.getIntValue(re.getString("id"),0);
                        mri.editModeDataShare(Util.getIntValue(curruserid,0),Util.getIntValue(BaseUtle.submodeid,0),dataid);
                        log.writeLog("部门管理员授权时权限重构,billid="+dataid+",userid="+userid+",formmodeid="+BaseUtle.submodeid);
                    }
                    //由于部门管理员可能修改  对科室管理员模块的数据权限进行重构 huangwm
                    restModeKsgly(subid);
                }
                if("1".equals(lx)){//部门
                    re.execute("select * from "+BaseUtle.bmbtable+" where bmmc="+depid);
                    if(re.next()){
                        int dataid=Util.getIntValue(re.getString("id"),0);
                        mri.editModeDataShare(Util.getIntValue(curruserid,0),Util.getIntValue(BaseUtle.depmodeid,0),dataid);
                        log.writeLog("科室管理员授权时权限重构,billid="+dataid+",userid="+userid+",formmodeid="+BaseUtle.depmodeid);
                    }
                }

            }
        }
        return mess;
    }
    /*
        取出不包含的数据
        from 参考的数据
        targ 里面的数据对比 from  如果不存在则返回

     */
    public static String getnotCludeStr(String from,String targ){
        String resultstr="";
        from = Util.null2String(from).trim();
        targ = Util.null2String(targ).trim();
        if("".equals(targ)){
            return "";
        }
        if("".equals(from)){
            return targ;
        }
        String[] demos=targ.split(",");
        for(String str:demos){
            str=Util.null2String(str).trim();
            if("".equals(str)){
                continue;
            }
            if((","+from+",").indexOf((","+str+","))<0){
                resultstr=resultstr+str+",";
            }
        }
        if(resultstr.endsWith(",")){
            resultstr=resultstr.substring(0,resultstr.length()-1);
        }
        return resultstr;
    }
    /*
        判断人员是否已经存在了其他的分部则不做校验
        如果当前人员  属于中山海关
     */
    public String checkSubOther(String subid,String userid){
        String mess="";
        DoorUtil doorUtil=new DoorUtil();
        String strzssubid=Util.null2String(doorUtil.getAllSub(BaseUtle.zshgsub+"")).trim() ;
        if((","+strzssubid+",").indexOf((","+subid+","))>-1){
            return "";
        }
        userid = Util.null2String(userid).trim();
        String[] userids=userid.split(",");
        RecordSet re=new RecordSet();
        for(String str:userids){
            str = Util.null2String(str).trim();
            String sql=" select b.Subcompanyname from  HrmSubcompanyDefined a left join HrmSubcompany b on a.subcomid=b.id  where  isnull(a.subcomid,0) not in ("+subid+") and ','+CAST( "+BaseUtle.subdefined+" as varchar(1000) )+',' like '%,"+str+",%' ";
            re.execute(sql);
            if(re.next()){
                User user=new User(Util.getIntValue(str,0));
                mess="部门["+re.getString("subcompanyname")+"]已存在管理员："+user.getLastname();
            }
        }
        return mess;
    }

    //这里不显示资产编码了，显示 卡片号，唯一标识，资产名称，目录代码块品牌，规格型号，单位名称，原使用部门，关联实物资产
    //其中单位名称和原使用部门都是文本在关保表里的
    public Map<String, Object> getTableData(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String kph=(String)Util.null2String(params.get("kph")) ;//卡片号
            String gdzcbm=(String)Util.null2String(params.get("gdzcbm")) ;//固定资产编码
            String gdzcmc=(String)Util.null2String(params.get("gdzcmc")) ;//固定资产名称

            //2021  0417  addby llf
            String pp=(String)Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String)Util.null2String(params.get("ggxh")) ;//规格型号

            //2021年6月23日 add by huangwm
            String sybm=(String)Util.null2String(params.get("sybm")) ;//使用部门

            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "ex17ecc14c-9d64-4a43-81a4-7b7c6f792857111111111";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());

            String sqlwhere =" 1=1 ";
            if(!"".equals(kph)){
                sqlwhere=sqlwhere+" and a.kph like '%"+kph+"%'";
            }

            if(!"".equals(gdzcbm)){
                sqlwhere=sqlwhere+" and a.gdzcbm like '%"+gdzcbm+"%'";
            }

            if(!"".equals(gdzcmc)){
                sqlwhere=sqlwhere+" and a.gdzcmc like '%"+gdzcmc+"%'";
            }
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp like '%"+pp+"%'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh like '%"+ggxh+"%'";
            }
            if(!"".equals(sybm)){
                sqlwhere=sqlwhere+" and a.sybm in ("+sybm+")";
            }
            String subid=getSubQxByUser(user);
            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)
            DoorUtil DoorUtil=new DoorUtil();
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
                log.writeLog("系统管理员");
                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(0+"")+")";
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+"")){//中山
                log.writeLog("中山海关系统管理员");
                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub("5")+")";
            }else if(BaseUtle.ckeckRole(user.getUID()+"",DoorAaction.jsjsub)){//缉私局
                log.writeLog("缉私局管理员" );
                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub("29")+")";
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
                log.writeLog("部门管理员" );
                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
            }else{
                log.writeLog("个人用户" );
                sqlwhere=sqlwhere+" and 1!=1";
            }
            log.writeLog("关保数据销账列表sqlwhere--->"+sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            String backfields =	" kpwybs,gbzcid,kph, gdzcbm, gdzcmc,ggxh,pp,dj, syrlastname,bz,sybm2,dwmc,mldm,subcompanyname ";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            //String fromSql=" from (select a.kpwybs,a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,a.syr syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm,d.subcompanyname subcompanyname from uf_uf_gbxtzczmxxexc a ,uf_gbxtzczmxx c left join HrmSubCompany d on c.sybm=d.id  where  a.kpwybs=c.kpwybs and len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1) and isnull(c.sybm,0) not in (5,29,13,8,15,6,7,41,40,39)   ) a "	;
            //2024年9月18日 增加distinct 解决uf_uf_gbxtzczmxxexc导致的数据重复问题
            String fromSql=" from (select distinct a.kpwybs,a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,a.syr syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm,d.subcompanyname subcompanyname from uf_uf_gbxtzczmxxexc a ,uf_gbxtzczmxx c left join HrmSubCompany d on c.sybm=d.id  where  a.kpwybs=c.kpwybs and len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            log.writeLog("关保数据销账列表fromSql--->"+fromSql);
            table.setBackfields(backfields);

            table.setSqlform(fromSql);
            table.setSqlwhere(sqlwhere);
            //table.setSqlorderby("gbzcid");
            //table.setSqlprimarykey("gbzcid");
            //kpwybs
            table.setSqlorderby("kpwybs");
            table.setSqlprimarykey("kpwybs");
            table.setSqlisdistinct("false");
            //卡片号，目录代码，固定资产名称，品牌，规格型号，所在部门2(表里有两个所在部门，取带有数字2的那个)，对应单位，关联实物资产(这个放后面)
            table.getColumns().add(new WeaTableColumn("kpwybs").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            table.getColumns().add(new WeaTableColumn("15%", "卡片唯一标识", "kpwybs","kpwybs"));
            table.getColumns().add(new WeaTableColumn("10%", "卡片号", "kph","kph"));
            table.getColumns().add(new WeaTableColumn("10%", "目录代码", "mldm","mldm"));
            table.getColumns().add(new WeaTableColumn("10%", "名称", "gdzcmc","gdzcmc"));
            table.getColumns().add(new WeaTableColumn("10%", "品牌", "pp","pp"));
            table.getColumns().add(new WeaTableColumn("13%", "型号", "ggxh","ggxh"));
            //table.getColumns().add(new WeaTableColumn("5%", "单价", "dj","dj"));
            //table.getColumns().add(new WeaTableColumn("5%", "使用人", "syrlastname","syrlastname"));
            table.getColumns().add(new WeaTableColumn("10%", "使用部门", "subcompanyname","subcompanyname"));
            //table.getColumns().add(new WeaTableColumn("5%", "单位名称", "dwmc","dwmc"));
            table.getColumns().add(new WeaTableColumn("20%", "实物资产", "swzc","swzc"));

            //增加右侧操作选项
            //weaTableOperates.setOperate(operateList);

            //table.setOperates(weaTableOperates);
            //table.setOperates(weaTableOperates);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }

    /**
     * 销账 确认执行动作
     * @param params
     * @param user
     * @return
     */
    public Map<String, Object> CanlenQr(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        String datavalue=Util.null2String(params.get("qrdata")).trim() ;
        String type=Util.null2String(params.get("type")).trim() ;//0:确认  1：撤销
        List<Map<String,Object>> sqllist=new  ArrayList<Map<String,Object>>();
        boolean flag=true;
        String mess="";
        try{
            if("".equals(datavalue)){
                apidatas.put("flag",flag);
                apidatas.put("mess","传入的确认数据为空 qrdata");
                return apidatas;
            }
            if(datavalue.endsWith(",")){
                datavalue=datavalue.substring(0,datavalue.length()-1);
            }
            RecordSet re=new RecordSet();
            String sql="select * from uf_xzqr where id in ("+datavalue+")";
            log.writeLog("CanlenQr"+sql);
            re.execute(sql);
            String newdata="";
            while(re.next()){
                String id=Util.null2String(re.getString("id")).trim();
                String swzcid= Util.null2String(re.getString("swzcid")).trim();
                String gbzcid= Util.null2String(re.getString("gbzcid")).trim();
                log.writeLog("swzcid-->"+swzcid);
                log.writeLog("gbzcid-->"+gbzcid);
                if("0".equals(type)){
                    if(!"".equals(swzcid)&&!"".equals(gbzcid)){
                        newdata=newdata+gbzcid+"$"+swzcid+",";
                        //设置更新数据
                        Object[] param=new Object[1];
                        String sql1="update uf_xzqr  set zt='0' where id=?";
                        //String sql1="update uf_swnewexception  set sfyxz='0' where kpwybh=?";
                        param[0]=id;
                        Map<String,Object> sqlmap=new HashMap<>();
                        sqlmap.put("sql",sql1);
                        sqlmap.put("params",param);
                        sqllist.add(sqlmap);
                        
                    }
                }else{
                    //设置更新数据
                    Object[] param=new Object[1];
                    String sql1="update uf_xzqr  set zt='1' where id=?";
                    //String sql1="update uf_swnewexception  set sfyxz='0' where kpwybh=?";
                    param[0]=id;
                    Map<String,Object> sqlmap=new HashMap<>();
                    sqlmap.put("sql",sql1);
                    sqlmap.put("params",param);
                    sqllist.add(sqlmap);

                    //第一更新 实物异常表
                    Object[] param2=new Object[1];
                    String sql12="update uf_swnewexception  set sfyxz='1' where swzcid=? and isnull(sfyxz,-1) in (3)";
                    //String sql1="update uf_swnewexception  set sfyxz='0' where kpwybh=?";
                    param2[0]=swzcid;
                    Map<String,Object> sqlmap2=new HashMap<>();
                    sqlmap2.put("sql",sql12);
                    sqlmap2.put("params",param2);
                    sqllist.add(sqlmap2);
                    //第二更新 关保异常表
                    Object[] param1=new Object[1];
                    //String sql11="update uf_uf_gbxtzczmxxexc  set sfyxz='0' where gbzcid=?";
                    String sql11="update uf_uf_gbxtzczmxxexc  set sfyxz='1' where kpwybs=? and isnull(sfyxz,-1) in (3)";
                    param1[0]=gbzcid;
                    Map<String,Object> sqlmap1=new HashMap<>();
                    sqlmap1.put("sql",sql11);
                    sqlmap1.put("params",param1);
                    sqllist.add(sqlmap1);
                    //更新  实物单价  来源于关保的  单价
                    String sql13="update uf_swzczmxx   set dj=(select top 1 dj from uf_gbxtzczmxx where kpwybs=? ) where id=? ";
                    Object[] param3=new Object[2];
                    param3[0]=gbzcid;
                    param3[1]=swzcid;
                    Map<String,Object> sqlmap3=new HashMap<>();
                    sqlmap3.put("sql",sql13);
                    sqlmap3.put("params",param3);
                    sqllist.add(sqlmap3);
                }

            }
            if(!"".equals(newdata)||sqllist.size()>0){
                if("0".equals(type)){
                    params.put("data",newdata);
                    params.put("sqllist",sqllist);
                    log.writeLog("gbzcid-begin->");
                    apidatas=Canlen(params,user);
                    return apidatas;
                }else if("1".equals(type)){
                    Uf_xzqrBaseService Uf_xzqrBaseService=new Uf_xzqrBaseService();
                    mess=Uf_xzqrBaseService.getObjMapList(null,sqllist);
                }
            }else{
                apidatas.put("flag",flag);
                apidatas.put("mess",mess);
                return apidatas;
            }
        }catch(Exception e){
            apidatas.put("flag",false);
            apidatas.put("mess", e.getMessage());
        }
        if(!"".equals(mess)){
            flag=false;
        }
        apidatas.put("flag",flag);
        apidatas.put("mess",mess);
        return apidatas;
    }

    //同步  销账
    public synchronized Map<String, Object>  CanlenCheck(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();

        return Canlen( params,  user); //直接销账

        //判断当前人员是否是 资产管理员  如果说的话直接销账
        //user=new User(9139);//测试用的
        /*
        if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")){
            log.writeLog("系统管理员销账");
            //if(false){
            return Canlen( params,  user);
        }else{
            //写入 待 确认的 界面

                boolean flag=true;
                String mess="";
                uf_xzqr uf_xzqr=null;
                List<Map<String,Object>> sqllist=new  ArrayList<Map<String,Object>>();
                List<Object> objlist=new ArrayList<Object>();
                String datavalue=Util.null2String(params.get("data")).trim() ;
                log.writeLog("关保对碰异常销账 "+datavalue);
                String[] datavalues= datavalue.split(",");
                for(String str:datavalues) {

                    str = Util.null2String(str).trim();
                    if ("".equals(str)) {
                        continue;
                    }
                    String[] strall = str.split("\\$");
                    if (strall.length == 2) {
                        //第一个 关保资产ID 第二个是实物资产ID
                        String gbid = Util.null2String(strall[0]).trim();
                        String swid = Util.null2String(strall[1]).trim();
                        if ("".equals(gbid) || "".equals(swid)) {
                            continue;
                        }
                        if(!XzUtil.ckeckCanle(swid, gbid)){
                            log.writeLog(swid+"实物<不匹配>关保"+gbid);
                            continue;
                        }
                        //XzUtil
                        uf_xzqr=new uf_xzqr();
                        uf_xzqr.setFqr(user.getUID());
                        uf_xzqr.setFqrbm(user.getUserSubCompany1());
                        uf_xzqr.setFqrks(user.getUserDepartment());
                        uf_xzqr.setSwzcid(swid);
                        uf_xzqr.setSwycid(XzUtil.getSwExidBySwid(swid));
                        uf_xzqr.setGbzcid(gbid);
                        uf_xzqr.setGbycid(XzUtil.getGbExidByGbid(gbid));
                        //分装额外的  数据
                        setOtherUf_xzqr(swid,gbid,uf_xzqr);
                        objlist.add(uf_xzqr);
                        log.writeLog("------------------------更新实物异常表-------------------------------start");
                        //第一更新 实物异常表
                        Object[] param=new Object[1];
                        String sql1="update uf_swnewexception  set sfyxz='3' where swzcid=? and isnull(sfyxz,-1) in (-1,1)";
                        log.writeLog("实物表id"+swid+" "+sql1);
                        //String sql1="update uf_swnewexception  set sfyxz='0' where kpwybh=?";
                        param[0]=swid;
                        Map<String,Object> sqlmap=new HashMap<>();
                        sqlmap.put("sql",sql1);
                        sqlmap.put("params",param);
                        sqllist.add(sqlmap);
                        log.writeLog("------------------------更新实物异常表-------------------------------end");

                        log.writeLog("------------------------更新关保异常表-------------------------------start");
                        //第二更新 关保异常表
                        Object[] param1=new Object[1];
                        //String sql11="update uf_uf_gbxtzczmxxexc  set sfyxz='0' where gbzcid=?";
                        String sql11="update uf_uf_gbxtzczmxxexc  set sfyxz='3' where kpwybs=? and isnull(sfyxz,-1) in (-1,1)";
                        log.writeLog("关保资产唯一标识>"+gbid+" "+sql11);
                        param1[0]=gbid;
                        Map<String,Object> sqlmap1=new HashMap<>();
                        sqlmap1.put("sql",sql11);
                        sqlmap1.put("params",param1);
                        sqllist.add(sqlmap1);
                        log.writeLog("------------------------更新关保异常表-------------------------------end");

                    }
                }
                if(objlist!=null&&objlist.size()>0){
                    Uf_xzqrBaseService Uf_xzqrBaseService=new Uf_xzqrBaseService();
                    mess=Uf_xzqrBaseService.getObjMapList(objlist,sqllist);
                }
                if(!"".equals(mess)){
                    flag=false;
                }
            apidatas.put("flag",flag);
            apidatas.put("mess",mess);
        }

        return apidatas;

         */
    }
    public void setOtherUf_xzqr(String swid,String gbid,uf_xzqr model){
        RecordSet re=new RecordSet();
        String sql="select kph,mldm,mlmc,gdzcmc,ggxh,pp,sybm from uf_gbxtzczmxx where kpwybs='"+gbid+"'";
        re.execute(sql);
        if(re.next()){
            String kph=Util.null2String(re.getString("kph"));
            String mldm=Util.null2String(re.getString("mldm"));
            String mlmc=Util.null2String(re.getString("mlmc"));
            String gdzcmc=Util.null2String(re.getString("gdzcmc"));
            String ggxh=Util.null2String(re.getString("ggxh"));
            String pp=Util.null2String(re.getString("pp"));
            int sybm=Util.getIntValue(re.getString("sybm"),0);
            model.setGbggxh(ggxh);
            model.setGbkph(kph);
            model.setGbmldm(mldm);
            model.setGbpp(pp);
            model.setGbsybm(sybm);
            model.setGbzclx(mlmc);

        }
        //实物
        sql="select swzcbh,zclx,zcmc,ggxh,pp,dybm from uf_swzczmxx where id="+swid;
        re.execute(sql);
        if(re.next()){
            String swzcbh=Util.null2String(re.getString("swzcbh"));
            String zclx=Util.null2String(re.getString("zclx"));
            String zcmc=Util.null2String(re.getString("zcmc"));
            String ggxh=Util.null2String(re.getString("ggxh"));
            String pp=Util.null2String(re.getString("pp"));
            int dybm=Util.getIntValue(re.getString("dybm"),0);
            model.setSwzcbh(swzcbh);
            model.setSwggxh(ggxh);
            model.setSwpp(pp);
            model.setSwsblx(zclx);
            model.setSwsbmc(zcmc);
            model.setSwsybm(dybm);
        }
    }
    /*
    撤销  销账
 关保资产撤销  实物  kpwybh  关保 kpwybs
 销账的 时候   需要 校验  是否可以销账
 Map<String, Object> apidatas = new HashMap<String, Object>();
        String datavalue=Util.null2String(params.get("qrdata")).trim() ;
        String type=Util.null2String(params.get("type")).trim() ;//0:确认  1：撤销
        List<Map<String,Object>> sqllist=new  ArrayList<Map<String,Object>>();
        boolean flag=true;
        String mess="";
        try{

            if("".equals(datavalue)){
                apidatas.put("flag",flag);
                apidatas.put("mess",mess);
                return apidatas;
            }
            if(datavalue.endsWith(",")){
                datavalue=datavalue.substring(0,datavalue.length()-1);
            }
            RecordSet re=new RecordSet();
            String sql="select * from uf_xzqr where id in ("+datavalue+")";
            re.execute(sql);
            String newdata="";
            while(re.next()){
                String id=Util.null2String(re.getString("id")).trim();
                String swzcid= Util.null2String(re.getString("swzcid")).trim();
                String gbzcid= Util.null2String(re.getString("gbzcid")).trim();

 */


    public Map<String, Object>  CalenCanlen(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String datavalue=Util.null2String(params.get("qrdata")).trim() ;
        String type=Util.null2String(params.get("type")).trim() ;//0:确认  1：撤销
        List<Map<String,Object>> sqllist=new  ArrayList<Map<String,Object>>();
        List<Object> objlist=new ArrayList<Object>();
        boolean flag=true;
        String mess="";
        try{

            if("".equals(datavalue)){
                apidatas.put("flag",flag);
                apidatas.put("mess",mess);
                return apidatas;
            }
            if(datavalue.endsWith(",")){
                datavalue=datavalue.substring(0,datavalue.length()-1);
            }
            RecordSet re=new RecordSet();
            String sql="select * from uf_xzqr where id in ("+datavalue+")";
            re.execute(sql);
            String newdata="";
            while(re.next()){
                String id=Util.null2String(re.getString("id")).trim();
                String swid= Util.null2String(re.getString("swzcid")).trim();
                String gbid= Util.null2String(re.getString("gbzcid")).trim();
                    //第一个 关保资产ID 第二个是实物资产ID
                    if("".equals(gbid)||"".equals(swid)){
                        continue;
                    }
                    if(!XzUtil.ckeckCanle(swid, gbid)){
                        log.writeLog(swid+"不匹配"+gbid);
                        continue;
                    }
                    //第一更新 实物异常表
                    Object[] param=new Object[1];
                    String sql1="update uf_swnewexception  set sfyxz='1' where swzcid=?";
                    //String sql1="update uf_swnewexception  set sfyxz='0' where kpwybh=?";
                    param[0]=swid;
                    Map<String,Object> sqlmap=new HashMap<>();
                    sqlmap.put("sql",sql1);
                    sqlmap.put("params",param);
                    sqllist.add(sqlmap);
                    //第二更新 关保异常表
                    Object[] param1=new Object[1];
                    //String sql11="update uf_uf_gbxtzczmxxexc  set sfyxz='0' where gbzcid=?";
                    String sql11="update uf_uf_gbxtzczmxxexc  set sfyxz='1' where kpwybs=?";
                    param1[0]=gbid;
                    Map<String,Object> sqlmap1=new HashMap<>();
                    sqlmap1.put("sql",sql11);
                    sqlmap1.put("params",param1);
                    sqllist.add(sqlmap1);

                    Object[] param3=new Object[1];
                    //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                    String sql13="update uf_gbxtzczmxx  set dyswzc='',glswzc='' where kpwybs=?";
                    param3[0]=gbid;

                    Map<String,Object> sqlmap3=new HashMap<>();
                    sqlmap3.put("sql",sql13);
                    sqlmap3.put("params",param3);
                    sqllist.add(sqlmap3);
                    //更新 实物资产表
                    JSONObject GBJSON=getLsInfoByid(gbid);
                    //获取历史的  实物 唯一号以及  卡片 号
                    if(GBJSON.size()>0){//kpwybh
                        Object[] param2=new Object[4];
                        String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=?  where id=?";
                        //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where kpwybh=?";
                        param2[0]=GBJSON.getString("kpwybs");
                        param2[1]=GBJSON.getString("kph");
                        param2[2]="";
                        param2[3]=swid;
                        Map<String,Object> sqlmap2=new HashMap<>();
                        sqlmap2.put("sql",sql12);
                        sqlmap2.put("params",param2);
                        sqllist.add(sqlmap2);


                    }else{
                        flag=false;
                        mess="没有获取关保数据";
                        break;
                    }

                    //插入销账记录
                    Uf_cxjlb Uf_cxjlb=new Uf_cxjlb();
                    Uf_cxjlb.setBz(user.getLastname()+":"+sim.format(new Date())+"进行了最终销账!");
                    Uf_cxjlb.setGbzcid(gbid);
                    Uf_cxjlb.setSwzcid(swid);
                    Uf_cxjlb.setXzr(user.getUID()+"");
                    Uf_cxjlb.setXzszks(user.getUserDepartment()+"");
                    Uf_cxjlb.setXzszbm(user.getUserSubCompany1()+"");
                    objlist.add(Uf_cxjlb);
                }
            log.writeLog("Canlencal"+objlist.toString());
            log.writeLog("Canlencal"+sqllist.toString());

            if(objlist!=null&&objlist.size()>0){
                Uf_cxjlbExceptionBaseService Uf_cxjlbExceptionBaseService=new Uf_cxjlbExceptionBaseService();
                mess= Util.null2String(Uf_cxjlbExceptionBaseService.getObjMapList(objlist,sqllist));
                if(!"".equals(mess)){
                    flag=false;
                }
            }
        }catch(Exception e){

        }
        apidatas.put("flag", flag);
        apidatas.put("mess", mess);
        return apidatas;
    }

   /*
    关保资产撤销  实物  kpwybh  关保 kpwybs
    销账的 时候   需要 校验  是否可以销账
    */
   public Map<String, Object>  Canlen(Map<String,Object> params, User user){
       Map<String, Object> apidatas = new HashMap<String, Object>();
       SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       boolean flag=true;
       String mess="";
       List<Map<String,Object>> sqllist=null;//new  ArrayList<Map<String,Object>>();
       List<Object> objlist=new ArrayList<Object>();
        try{
           String datavalue=Util.null2String(params.get("data")).trim() ;
            sqllist=(List<Map<String,Object>>)params.get("sqllist");
            if(sqllist==null){
                sqllist=new  ArrayList<Map<String,Object>>();
            }else{
                log.writeLog("sqllist--->"+sqllist.toString());
            }
           log.writeLog("Canlen"+datavalue);
           String[] datavalues= datavalue.split(",");
           for(String str:datavalues){

                str=Util.null2String(str).trim() ;
                if("".equals(str)){
                    continue;
                }
               String[] strall= str.split("\\$");
                if(strall.length==2){
                    //第一个 关保资产ID 第二个是实物资产ID
                    String gbid=Util.null2String(strall[0]).trim();
                    String swid=Util.null2String(strall[1]).trim();
                    if("".equals(gbid)||"".equals(swid)){
                        continue;
                    }
                    if(!XzUtil.ckeckCanle(swid, gbid)){
                        log.writeLog(swid+"不匹配"+gbid);
                        continue;
                    }
                    //第一更新 实物异常表
                    Object[] param=new Object[1];
                    String sql1="update uf_swnewexception  set sfyxz='0' where swzcid=?";
                    //String sql1="update uf_swnewexception  set sfyxz='0' where kpwybh=?";
                    param[0]=swid;
                    Map<String,Object> sqlmap=new HashMap<>();
                    sqlmap.put("sql",sql1);
                    sqlmap.put("params",param);
                    sqllist.add(sqlmap);
                    //第二更新 关保异常表
                    Object[] param1=new Object[1];
                    //String sql11="update uf_uf_gbxtzczmxxexc  set sfyxz='0' where gbzcid=?";
                    String sql11="update uf_uf_gbxtzczmxxexc  set sfyxz='0' where kpwybs=?";
                    param1[0]=gbid;
                    Map<String,Object> sqlmap1=new HashMap<>();
                    sqlmap1.put("sql",sql11);
                    sqlmap1.put("params",param1);
                    sqllist.add(sqlmap1);

                    log.writeLog("------------------------更新关保建模表关联实物id-------------------------------start");
                    Object[] param3=new Object[3];
                    //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                    String sql13="update uf_gbxtzczmxx  set dyswzc=?,glswzc=? where kpwybs=?";
                    param3[0]=swid;
                    param3[1]=1;
                    param3[2]=gbid;
                    Map<String,Object> sqlmap3=new HashMap<>();
                    sqlmap3.put("sql",sql13);
                    sqlmap3.put("params",param3);
                    sqllist.add(sqlmap3);
                    log.writeLog("------------------------更新关保建模表关联实物id-------------------------------start");
                    //更新 实物资产表
                    JSONObject GBJSON=getGbInfoByid(gbid);
                    if(GBJSON.size()>0){//kpwybh
                        log.writeLog("------------------------更新实物资产表单价，关联关保资产，卡片号-------------------------------start");
                        Object[] param2=new Object[5];
                        //更新  实物单价  来源于关保的  单价，关联关保资产字段，卡片号
                        String sql12="update uf_swzczmxx  set dj=(select top 1 dj from uf_gbxtzczmxx where kpwybs=? ), kpwybh=?,kph=?,xzgbxtzc=?,lskpwyh=lskpwyh+','+kpwybh,lskph=lskph+','+kph  where id=?";
                        //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where kpwybh=?";
                        param2[0]=gbid;
                        param2[1]=GBJSON.getString("kpwybs");
                        param2[2]=GBJSON.getString("kph");
                        param2[3]=gbid;
                        param2[4]=swid;
                        Map<String,Object> sqlmap2=new HashMap<>();
                        sqlmap2.put("sql",sql12);
                        sqlmap2.put("params",param2);
                        sqllist.add(sqlmap2);
                        log.writeLog("------------------------更新实物资产表单价，关联关保资产，卡片号-------------------------------end");
                    }else{
                        flag=false;
                        mess="没有获取关保数据";
                        break;
                    }

                    //插入销账记录
                    Uf_cxjlb Uf_cxjlb=new Uf_cxjlb();
                    Uf_cxjlb.setBz(user.getLastname()+":"+sim.format(new Date())+"进行了最终销账!");
                    Uf_cxjlb.setGbzcid(gbid);
                    Uf_cxjlb.setSwzcid(swid);
                    Uf_cxjlb.setXzr(user.getUID()+"");
                    Uf_cxjlb.setXzszks(user.getUserDepartment()+"");
                    Uf_cxjlb.setXzszbm(user.getUserSubCompany1()+"");
                    objlist.add(Uf_cxjlb);
               }
           }
           log.writeLog("Canlen"+objlist.toString());
           log.writeLog("Canlen"+sqllist.toString());

           if(objlist!=null&&objlist.size()>0){
               Uf_cxjlbExceptionBaseService Uf_cxjlbExceptionBaseService=new Uf_cxjlbExceptionBaseService();
               mess= Util.null2String(Uf_cxjlbExceptionBaseService.getObjMapList(objlist,sqllist));
               if(!"".equals(mess)){
                    flag=false;
               }
           }
        }catch(Exception e){

        }
       apidatas.put("flag", flag);
       apidatas.put("mess", mess);
       return apidatas;
   }
   /*
    获取  关保信息
    */
   public JSONObject getGbInfoByid(String id){
       JSONObject json=new JSONObject();
       RecordSet re=new RecordSet();
       //String sql="select * from uf_gbxtzczmxx where id="+id;
       String sql="select * from uf_gbxtzczmxx where kpwybs='"+id+"'";
       re.execute(sql);
       while(re.next()){
            String kpwybs=Util.null2String(re.getString("kpwybs"));
           String kph=Util.null2String(re.getString("kph"));
           json.put("kpwybs", kpwybs);
           json.put("kph", kph);
       }
       return json;
   }

    /**
     * 获取  实物 资产的  历史的  卡片号 以及 卡片唯一号
     * @param id
     * @return
     */
    public JSONObject getLsInfoByid(String id){
        JSONObject json=new JSONObject();
        RecordSet re=new RecordSet();
        String lskpwyh="";
        String lskph="";
        //String sql="select * from uf_gbxtzczmxx where id="+id;
        String sql="select lskpwyh,lskph from uf_swzczmxx where id='"+id+"'";
        re.execute(sql);
        while(re.next()){
            lskpwyh=Util.null2String(re.getString("lskpwyh"));
            lskph=Util.null2String(re.getString("lskph"));

        }
        String[] lskpwyhs=lskpwyh.split(",");
        String[] lskphs=lskph.split(",");
        json.put("kpwybs", lskpwyhs[0]);
        json.put("kph", lskphs[0]);
        return json;
    }
     /*
       *  字段联动获取资产的没错
       *  实物资产：swzcbh 编号，zclx设备类型，pp品牌，ggxh规格型号，rkrq入库日期
       *  关宝： kph 卡片号，mldm目录代码，gdzcmc固定资产名称，pp品牌，ggxh规格型号
       * 实物  kpwybh  关保 kpwybs
       */
    public JSONArray getZcinfo(HttpServletRequest var1, HttpServletResponse var2){
        String id= Util.null2String(var1.getParameter("id")) ;//资产
        String lx= Util.null2String(var1.getParameter("lx")) ;//类型 0:关宝  1：实物
        JSONArray jsons=new JSONArray();
        if("0".equals(lx)){
            //jsons=getTableBaseInfo("select gdzcmc lastname,kph,mldm,pp,ggxh from uf_gbxtzczmxx where id="+id,new String[]{"lastname","kph","mldm","pp","ggxh"});//生产需要替换  关保
            jsons=getTableBaseInfo("select gdzcmc lastname,kph,mldm,pp,ggxh from uf_gbxtzczmxx where kpwybs='"+id+"'",new String[]{"lastname","kph","mldm","pp","ggxh"});//生产需要替换  关保
        }else if("1".equals(lx)){
            //jsons=getTableBaseInfo("select zcmc lastname,swzcbh,pp,ggxh,rkrq,b.flmc zclx  from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id where a.id="+id,new String[]{"lastname","swzcbh","pp","ggxh","rkrq","zclx"});//生产需要替换      实物
            jsons=getTableBaseInfo("select zcmc lastname,swzcbh,d.ppmc pp,c.ggxh,rkrq,b.flmc zclx,e.lastname zrr,f.subcompanyname dybm  from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id left join hrmresource e on a.zrr=e.id left join HrmSubCompany f on a.dybm=f.id where a.id='"+id+"'",new String[]{"lastname","swzcbh","pp","ggxh","rkrq","zclx","zrr","dybm"});//生产需要替换      实物
        }
        return jsons;
    }
    public JSONArray getTableBaseInfo(String sql,String[] field ){
        log.writeLog(sql);
        JSONArray jsons=new JSONArray();
        JSONObject json=null;
        RecordSet re=new RecordSet();
        sql=Util.null2String(sql).trim();
        if(!"".equals(sql)&&field!=null){
            re.execute(sql);
            while(re.next()){
                json=new JSONObject();
                for(String str:field){
                    str=Util.null2String(str).trim();
                    if("".equals(str)){
                        continue;
                    }
                    String value=Util.null2String(re.getString(str));
                    json.put(str.toLowerCase(),value);
                }
                jsons.add(json);
            }
        }
        return jsons;
    }
    public JSONObject getTableBaseInfoJSON(String sql,String[] field ){
        log.writeLog(sql);

        JSONObject json=null;
        RecordSet re=new RecordSet();
        sql=Util.null2String(sql).trim();
        if(!"".equals(sql)&&field!=null){
            re.execute(sql);
            if(re.next()){
                json=new JSONObject();
                for(String str:field){
                    str=Util.null2String(str).trim();
                    if("".equals(str)){
                        continue;
                    }
                    String value=Util.null2String(re.getString(str));
                    json.put(str.toLowerCase(),value);
                }

            }
        }
        return json;
    }
    /*
        初始化选中的 资产数据
        实物  kpwybh  关保 kpwybs
     */
    public JSONArray getIniZcJson(HttpServletRequest var1, HttpServletResponse var2){
        JSONArray jsons=new JSONArray();

        String ids=Util.null2String(var1.getParameter("ids")).trim();
        log.writeLog("getIniZcJson"+ids);
        if(!"".equals(ids)){
            String[] idsall=ids.split(",");
            for(String str:idsall){
                str=Util.null2String(str).trim();
                if("".equals(str)){
                    continue;
                }
                String[] zcid= str.split("\\$");
                if(zcid!=null&&zcid.length==2){
                    String gbid=Util.null2String(zcid[0]).trim();
                    String swid=Util.null2String(zcid[1]).trim();
                    if("".equals(gbid)){
                        continue;
                    }
                    //实物资产：swzcbh 编号，zclx设备类型，pp品牌，ggxh规格型号，rkrq入库日期
                    //关宝： kph 卡片号，mldm目录代码，gdzcmc固定资产名称，pp品牌，ggxh规格型号
                    //开始拼接数据
                    //这里显示卡片号，资产名称，目录代码，品牌，规格型号 20210223  
                    //实物资产编号，设备类型，品牌，规格型号，使用部门，责任人
                    JSONObject jsonval=new JSONObject();
                    //JSONObject demojson=getTableBaseInfoJSON("select id gbzc,gdzcbm,gdzcmc gbzcmc,gdzcbm gbzcspan,kph,mldm,gdzcmc,pp,ggxh from uf_gbxtzczmxx where id='"+gbid+"' ",new String[]{"gbzc","gbzcmc","gbzcspan","kph","mldm","gdzcmc","pp","ggxh"});//关宝资产
                    //JSONObject demojson=getTableBaseInfoJSON("select kpwybs gbzc,gdzcbm,gdzcmc gbzcmc,gdzcbm gbzcspan,kph,mldm,gdzcmc,pp,ggxh from uf_gbxtzczmxx where kpwybs='"+gbid+"' ",new String[]{"gbzc","gbzcmc","gbzcspan","kph","mldm","gdzcmc","pp","ggxh"});//关宝资产
                    JSONObject demojson=getTableBaseInfoJSON("select kpwybs gbzc,gdzcbm,gdzcmc gbzcmc,kph gbzcspan,kph,mldm,gdzcmc,pp,ggxh from uf_gbxtzczmxx where kpwybs='"+gbid+"' ",new String[]{"gbzc","gbzcmc","gbzcspan","kph","mldm","gdzcmc","pp","ggxh"});//关宝资产
                    jsonval.put("id",UUID.randomUUID()+"");
                    jsonval.put("gbzc",Util.null2String(demojson.getString("gbzc")));
                    jsonval.put("gbzcmc",Util.null2String(demojson.getString("gbzcmc")));
                    jsonval.put("gbzcspan",Util.null2String(demojson.getString("gbzcspan")));
                    jsonval.put("kph",Util.null2String(demojson.getString("kph")));
                    jsonval.put("mldm",Util.null2String(demojson.getString("mldm")));
                    jsonval.put("gdzcmc",Util.null2String(demojson.getString("gdzcmc")));
                    jsonval.put("pp",Util.null2String(demojson.getString("pp")));
                    jsonval.put("ggxh",Util.null2String(demojson.getString("ggxh")));
                    //JSONObject swdemojson=getTableBaseInfoJSON("select a.id swzc,a.swzcbh swzcspan,b.flmc zclx,a.pp swpp,a.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id where a.id='"+swid+"'",new String[]{"swzc","swzcspan","zclx","swpp","swggxh","rkrq"});//实物资产
                    //JSONObject swdemojson=getTableBaseInfoJSON("select a.id swzc,a.swzcbh swzcspan,b.flmc zclx,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id where a.id='"+swid+"'",new String[]{"swzc","swzcspan","zclx","swpp","swggxh","rkrq"});//实物资产
                    JSONObject swdemojson=getTableBaseInfoJSON("select a.id swzc,a.swzcbh swzcspan,b.flmc zclx,d.ppmc swpp,c.ggxh swggxh,a.rkrq,e.lastname zrr,f.subcompanyname dybm from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id left join hrmresource e on a.zrr=e.id left join HrmSubCompany f on a.dybm=f.id where a.id='"+swid+"'",new String[]{"swzc","swzcspan","zclx","swpp","swggxh","rkrq","zrr","dybm"});//实物资产
                    jsonval.put("swzc",Util.null2String(swdemojson.getString("swzc")));
                    jsonval.put("swzcspan",Util.null2String(swdemojson.getString("swzcspan")));
                    jsonval.put("zclx",Util.null2String(swdemojson.getString("zclx")));
                    jsonval.put("swpp",Util.null2String(swdemojson.getString("swpp")));
                    jsonval.put("swggxh",Util.null2String(swdemojson.getString("swggxh")));
                    jsonval.put("rkrq",Util.null2String(swdemojson.getString("rkrq")));
                    jsonval.put("zrr",Util.null2String(swdemojson.getString("zrr")));
                    jsonval.put("dybm",Util.null2String(swdemojson.getString("dybm")));
                    jsons.add(jsonval);
                }
            }
        }
        log.writeLog(jsons.toJSONString());
        return jsons;
    }

    //帐实关联 布局 关保列表
    // //关保的:hth合同号，pp品牌，ggxh规格型号，zclx资产类型(浏览单选)，kpzt卡片状态(选择框)
    public Map<String, Object> getTableDataG(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String hth=(String)Util.null2String(params.get("hth")) ;//合同号
            String pp=(String)Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String)Util.null2String(params.get("ggxh")) ;//规格型号
            String zclx=(String)Util.null2String(params.get("zclx")) ;//资产类型(浏览单选)
            String kpzt=(String)Util.null2String(params.get("kpzt")) ;//卡片状态(选择框)
            String rq=(String)Util.null2String(params.get("rq")) ;//取得日期


            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "gb17ecc14c-9d64-4a43-81a4-7b7c6f792857111111111";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());

            String sqlwhere =" 1=1 ";
            if(!"".equals(hth)){
                sqlwhere=sqlwhere+" and a.hth like '%"+hth+"%'";
            }
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp like '%"+pp+"%'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh like '%"+ggxh+"%'";
            }
            if(!"".equals(zclx)){
                sqlwhere=sqlwhere+" and a.mlmc='"+zclx+"'";
            }
            if(!"".equals(kpzt)){
                sqlwhere=sqlwhere+" and a.kpzt='"+kpzt+"'";
            }
            if(!"".equals(rq)){
                sqlwhere=sqlwhere+" and a.qdrq='"+rq+"'";
            }
            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)
            String subid=getSubQxByUser(user);
//            DoorUtil DoorUtil=new DoorUtil();
//            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
//                sqlwhere=sqlwhere+" and 1=1";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
//                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
//                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
//            }else{
//                sqlwhere=sqlwhere+" and 1!=1";
//            }
            if("".equals(subid)){
                sqlwhere=sqlwhere+" and 1!=1";
            }else{
                //增加过滤事业单位部门id
                sqlwhere=sqlwhere+" and a.sybm in ( "+subid+" ) ";
            }
            log.writeLog("sqlwhere--->"+sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            String backfields =	" id,kpwybs,kph, gdzcbm, gdzcmc,ggxh,pp,dj, syrlastname,bz,sybm2,dwmc,mldm,qdrq,zclxmc ";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            String fromSql=" from (select e.zclxmc,a.qdrq, a.id,a.kpzt,a.hth,a.kpwybs,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,a.syr syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_gbxtzczmxx a  left join uf_gbxtzczmxx c on a.kpwybs=c.kpwybs left join uf_gzcmldm e on a.mlmc=e.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and len(isnull(a.dyswzc,''))=0 and isnull(a.glswzc,-1) in (-1,0) and isnull(a.sybm,0) not in (5,29,13,8,15,6,7,41,40,39)  and "+sqlwhere+" ) a ";
            log.writeLog("fromsql--->"+fromSql);

            table.setBackfields(backfields);
            table.setSqlform(fromSql);
            //sqlwhere 放到formsql里 huangwm 2021年2月4日10:09:55
            //table.setSqlwhere(sqlwhere);
            table.setSqlorderby("kph asc");//根据卡片号排

            //table.setSqlprimarykey("gbzcid");
            //kpwybs  kpwybs
            //table.setSqlorderby("id");//kpwybs
            table.setSqlprimarykey("kpwybs");
            table.setSqlisdistinct("false");
            //卡片号，目录代码，固定资产名称，品牌，规格型号，所在部门2(表里有两个所在部门，取带有数字2的那个)，对应单位，关联实物资产(这个放后面)
            table.getColumns().add(new WeaTableColumn("kpwybs").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            //table.getColumns().add(new WeaTableColumn("10%", "资产编码", "gdzcbm","gdzcbm"));
            table.getColumns().add(new WeaTableColumn("9%", "卡片号", "kph","kph","com.api.hg.util.TranceUtil.getGbTitle").setOtherpara("column:id"));
            table.getColumns().add(new WeaTableColumn("10%", "资产类型", "zclxmc","zclxmc"));
            table.getColumns().add(new WeaTableColumn("8%", "资产名称", "gdzcmc","gdzcmc"));
            table.getColumns().add(new WeaTableColumn("8%", "资产品牌", "pp","pp"));
            table.getColumns().add(new WeaTableColumn("10%", "资产型号", "ggxh","ggxh"));
            //table.getColumns().add(new WeaTableColumn("5%", "使用部门", "sybm2","sybm2"));
            //table.getColumns().add(new WeaTableColumn("5%", "使用单位", "dwmc","dwmc"));
            table.getColumns().add(new WeaTableColumn("8%", "取得日期", "qdrq","qdrq"));
            //table.getColumns().add(new WeaTableColumn("15%", "实物资产", "swzc","swzc"));

            //增加右侧操作选项
            //weaTableOperates.setOperate(operateList);

            //table.setOperates(weaTableOperates);
            //table.setOperates(weaTableOperates);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }
    //销账 布局 实物列表
    //实物的：hth 合同号，pp 品牌(浏览单选)，ggxh规格型号(浏览单选)，sblx设备类型(浏览单选)，sbzt设备状态(公共选择框)
    public Map<String, Object> getTableDataSW(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String pp=(String)Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String)Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String)Util.null2String(params.get("sblx")) ;//设备类型
            String sbzt=(String)Util.null2String(params.get("sbzt")) ;//设备状态
            String rq=(String)Util.null2String(params.get("rq")) ;//入库日期
            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "sw17ecc14c-9d64-4a43-81a4-7b7c6f792857111111111";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());

            String sqlwhere =" 1=1 ";
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp ='"+pp+"'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh ='"+ggxh+"'";
            }
            if(!"".equals(sblx)){
                sqlwhere=sqlwhere+" and a.zclx='"+sblx+"'";
            }
            if(!"".equals(sbzt)){
                sqlwhere=sqlwhere+" and a.zczt='"+sbzt+"'";
            }
            if(!"".equals(rq)){
                sqlwhere=sqlwhere+" and a.rkrq='"+rq+"'";
            }
            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)
            String subid=getSubQxByUser(user);
//            DoorUtil DoorUtil=new DoorUtil();
//            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
//                sqlwhere=sqlwhere+" and 1=1";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
//                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
//                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
//            }else{
//                sqlwhere=sqlwhere+" and 1!=1";
//            }
            if("".equals(subid)){
                sqlwhere=sqlwhere+" and 1!=1";
            }else{
                sqlwhere=sqlwhere+" and a.dybm in ("+subid+")";
            }
            log.writeLog(sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            String backfields =	" id,ggxh,pp,zczt,swzcspan,swzc,zclx,zclxmc,swpp,swggxh,rkrq";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            String fromSql=" from (select   a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id where len(isnull(a.xzgbxtzc,''))<=0  and  "+sqlwhere+" ) a1 "	;

            log.writeLog(fromSql);
            table.setBackfields(backfields);

            table.setSqlform(fromSql);
            //table.setSqlwhere(sqlwhere);
            //table.setSqlorderby("gbzcid");
            //table.setSqlprimarykey("gbzcid");
            //kpwybs
            table.setSqlorderby("id");//swzc
            table.setSqlprimarykey("id");
            table.setSqlisdistinct("false");
            //卡片号，目录代码，固定资产名称，品牌，规格型号，所在部门2(表里有两个所在部门，取带有数字2的那个)，对应单位，关联实物资产(这个放后面)
            table.getColumns().add(new WeaTableColumn("id").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            table.getColumns().add(new WeaTableColumn("10%", "实物资产编号", "swzcspan","swzcspan","com.api.hg.util.TranceUtil.getSwTitle").setOtherpara("column:id"));
            table.getColumns().add(new WeaTableColumn("10%", "设备类型", "zclxmc","zclxmc"));
            table.getColumns().add(new WeaTableColumn("10%", "品牌", "swpp","swpp"));
            table.getColumns().add(new WeaTableColumn("10%", "规格型号", "swggxh","swggxh"));
            table.getColumns().add(new WeaTableColumn("10%", "入库日期", "rkrq","rkrq"));

            //增加右侧操作选项
            //weaTableOperates.setOperate(operateList);

            //table.setOperates(weaTableOperates);
            //table.setOperates(weaTableOperates);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }
    //销账 布局 关保列表
    // //关保的:hth合同号，pp品牌，ggxh规格型号，zclx资产类型(浏览单选)，kpzt卡片状态(选择框)
    public Map<String, Object> getEditTableDataG(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String hth=(String)Util.null2String(params.get("hth")) ;//合同号
            String pp=(String)Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String)Util.null2String(params.get("ggxh")) ;//规格型号
            String zclx=(String)Util.null2String(params.get("zclx")) ;//资产类型(浏览单选)
            String kpzt=(String)Util.null2String(params.get("kpzt")) ;//卡片状态(选择框)



            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "17ecc14c-9d64-4a43-81a4-7b7c6f792857111111111";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());

            String sqlwhere =" 1=1 ";
            if(!"".equals(hth)){
                sqlwhere=sqlwhere+" and a.hth like '%"+hth+"%'";
            }
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp like '%"+pp+"%'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh like '%"+ggxh+"%'";
            }
            if(!"".equals(zclx)){
                sqlwhere=sqlwhere+" and a.mlmc='"+zclx+"'";
            }
            if(!"".equals(kpzt)){
                sqlwhere=sqlwhere+" and a.kpzt='"+kpzt+"'";
            }
            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)
            String subid=getSubQxByUser(user);
//            DoorUtil DoorUtil=new DoorUtil();
//            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
//                sqlwhere=sqlwhere+" and 1=1";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
//                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
//                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
//            }else{
//                sqlwhere=sqlwhere+" and 1!=1";
//            }
            if("".equals(subid)){
                sqlwhere=sqlwhere+" and 1!=1";
            }else{
                sqlwhere=sqlwhere+" and a.sybm in ("+subid+")";
            }
            log.writeLog(sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            String backfields =	" id,kpwybs,kph, gdzcbm, gdzcmc,ggxh,pp,dj, syrlastname,bz,sybm2,dwmc,mldm ";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            String fromSql=" from (select TOP 100 a.id,a.kpzt,a.hth,a.kpwybs,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,a.syr syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_gbxtzczmxx a  left join uf_gbxtzczmxx c on a.kpwybs=c.kpwybs where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and len(isnull(a.dyswzc,''))=0 and isnull(a.glswzc,-1) in (-1,0) and "+sqlwhere+" ) a "	;


            JSONObject tablejson=new JSONObject();
            JSONArray tables=new JSONArray();
            RecordSet re1=new RecordSet();
            //String sql="select "+backfields+" "+fromSql+" where "+sqlwhere;
            String sql="select "+backfields+" "+fromSql;
            log.writeLog(sql);
            re1.execute(sql);
            while(re1.next()){
                String id=Util.null2String(re1.getString("id"));
                String gdzcbm=Util.null2String(re1.getString("gdzcbm"));
                String kph=Util.null2String(re1.getString("kph"));
                String mldm=Util.null2String(re1.getString("mldm"));
                String gdzcmc=Util.null2String(re1.getString("gdzcmc"));
                String sybm2=Util.null2String(re1.getString("sybm2"));
                String dwmc=Util.null2String(re1.getString("dwmc"));
                //String swzc=Util.null2String(re1.getString("swzc"));
                tablejson=new JSONObject();
                tablejson.put("id", id);
                tablejson.put("gdzcbm", gdzcbm);
                tablejson.put("kph", kph);
                tablejson.put("mldm", mldm);
                tablejson.put("gdzcmc", gdzcmc);
                tablejson.put("sybm2", sybm2);
                tablejson.put("dwmc", dwmc);
                //tablejson.put("swzc", swzc);
                tables.add(tablejson);
            }
            apidatas.put("data",tables);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }
    //销账 布局 实物列表  Edit可编辑列表
    //实物的：hth 合同号，pp 品牌(浏览单选)，ggxh规格型号(浏览单选)，sblx设备类型(浏览单选)，sbzt设备状态(公共选择框)
    public Map<String, Object> getEditTableDataSW(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String pp=(String)Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String)Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String)Util.null2String(params.get("sblx")) ;//设备类型
            String sbzt=(String)Util.null2String(params.get("sbzt")) ;//设备状态


            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "17ecc14c-9d64-4a43-81a4-7b7c6f792857111111111";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());

            String sqlwhere =" 1=1 ";
            if(!"".equals(pp)){
                sqlwhere=sqlwhere+" and a.pp ='"+pp+"'";
            }
            if(!"".equals(ggxh)){
                sqlwhere=sqlwhere+" and a.ggxh ='"+ggxh+"'";
            }
            if(!"".equals(sblx)){
                sqlwhere=sqlwhere+" and a.zclx='"+sblx+"'";
            }
            if(!"".equals(sbzt)){
                sqlwhere=sqlwhere+" and a.zczt='"+sbzt+"'";
            }
            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)
            String subid=getSubQxByUser(user);
//            DoorUtil DoorUtil=new DoorUtil();
//            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
//                sqlwhere=sqlwhere+" and 1=1";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
//                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
//                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
//            }else{
//                sqlwhere=sqlwhere+" and 1!=1";
//            }
            if("".equals(subid)){
                sqlwhere=sqlwhere+" and 1!=1";
            }else{
                sqlwhere=sqlwhere+" and a.dybm in ("+subid+")";
            }
            log.writeLog(sqlwhere);

            JSONObject tablejson=new JSONObject();
            JSONArray tables=new JSONArray();

            String backfields =	" id,ggxh,pp,zczt,swzc,swzcspan, zclx,zclxmc,swpp,swggxh,rkrq";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            String fromSql=" from (select TOP 100 a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id where len(isnull(a.xzgbxtzc,''))<=0  and  "+sqlwhere+") a1 "	;

            log.writeLog(fromSql);
            RecordSet re1=new RecordSet();
            //String sql="select "+backfields+" "+fromSql+" where "+sqlwhere;
            String sql="select "+backfields+" "+fromSql;
            re1.execute(sql);
            while(re1.next()){
                String id=Util.null2String(re1.getString("id"));
                String swzcbh=Util.null2String(re1.getString("swzcbh"));
                String zclxmc=Util.null2String(re1.getString("zclxmc"));
                String swpp=Util.null2String(re1.getString("swpp"));
                String swggxh=Util.null2String(re1.getString("swggxh"));
                String rkrq=Util.null2String(re1.getString("rkrq"));
                tablejson=new JSONObject();
                tablejson.put("id", id);
                tablejson.put("swzcbh", swzcbh);
                tablejson.put("zclxmc", zclxmc);
                tablejson.put("swpp", swpp);
                tablejson.put("swggxh", swggxh);
                tablejson.put("rkrq", rkrq);
                tables.add(tablejson);
            }

            apidatas.put("data",tables);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }
    /*
        获取当前人员的分不权限

     */
    public String getSubQxByUser(User user){
        String subid="";
        DoorUtil DoorUtil=new DoorUtil();
        if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
            subid=DoorUtil.getAllSub(0+"");
        }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
            subid=DoorUtil.getAllSub(user.getUserSubCompany1()+"");
        }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
            subid=user.getUserSubCompany1()+"";
        }else{
            subid="";
        }
        return subid;
    }
    /*
      获取当前人员的分不权限（排除管理员）

   */
    public String getSubQxByUserNotadmin(User user){
        String subid="";
        DoorUtil DoorUtil=new DoorUtil();
        if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
            subid=DoorUtil.getAllSub(user.getUserSubCompany1()+"");
        }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
            subid=user.getUserSubCompany1()+"";
        }else{
            subid="";
        }
        return subid;
    }

    /*
    根据资产的ID 或取数据  type 0:实物 1：关保
    */
    public List<JSONObject> getZcInfos(String ids,String type){
        List<JSONObject> list=new ArrayList<>();
        ids=Util.null2String(ids).trim();
        if("".equals(ids)){
            return list;
        }
        if(ids.endsWith(",")){
            ids=ids.substring(0,ids.length()-1);
        }
        RecordSet re=new RecordSet();
        String sql ="";
        if("0".equals(type)){//实物
            sql="select a.id wyh,a.zcmc,a.pp as pp,a.ggxh as ggxh from uf_swzczmxx a where a.id in("+ids+")";
        }else if("1".equals(type)){//关保
            sql="select a.kpwybs wyh,a.gdzcmc zcmc,a.kph,a.pp as pp,a.ggxh as ggxh from uf_gbxtzczmxx a where a.kpwybs in("+XzUtil.getStrDh(ids)+")";
        }
        re.execute(sql);
        while(re.next()){
            String wyh=Util.null2String(re.getString("wyh")).trim();
            String zcmc=Util.null2String(re.getString("zcmc")).trim();
            String kph=Util.null2String(re.getString("kph")).trim();
            String pp=Util.null2String(re.getString("pp")).trim();
            String ggxh=Util.null2String(re.getString("ggxh")).trim();
            JSONObject json=new JSONObject();
            json.put("code", wyh);
            json.put("zcmc",zcmc);
            json.put("pp",pp);
            json.put("ggxh",ggxh);
            if("1".equals(type)){
                json.put("kph",kph);
            }
            list.add(json);
        }
        return list;
    }

    /*
         新的销账接口--帐实关联匹配
     */
    public synchronized String XiaoZhang(Map<String,Object> params, User user){
        String errormess="";
        List<Object> objlist=new ArrayList<Object>();
        try{
            String swzc=Util.null2String(params.get("swzc")).trim();
            String gbzc=Util.null2String(params.get("gbzc")).trim();
            log.writeLog("XiaoZhang-swzc->"+swzc);
            log.writeLog("XiaoZhang-gbzc->"+gbzc);
            List<JSONObject> swjsons=getZcInfos(swzc,"0");//实物资产唯一号有为空de情况
            List<JSONObject> gbjsons=getZcInfos(gbzc,"1");
            if(swjsons.size()!=gbjsons.size()){
                return "销账数据不一致请检查:实物"+swjsons.size()+" 关保"+gbjsons.size();
            }
            //拼接  sql
            List<Map<String,Object>> sqllist=new ArrayList<>();
            for(int i=0;i<swjsons.size();i++){
               JSONObject swjson= swjsons.get(i);
               JSONObject gbjson=gbjsons.get(i);
                if(swjson==null||gbjson==null){
                    return "遍历数据异常!";
                }
                //更新关保关联
                Object[] param2=new Object[3];
                //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                String sql12="update uf_gbxtzczmxx  set dyswzc=?,glswzc=? where kpwybs=?";
                param2[0]=swjson.getString("code");
                param2[1]=1;
                param2[2]=gbjson.getString("code");
                Map<String,Object> sqlmap2=new HashMap<>();
                sqlmap2.put("sql",sql12);
                sqlmap2.put("params",param2);
                sqllist.add(sqlmap2);

                //更新实物关联
                Object[] param3=new Object[4];
                //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                String sql13="update uf_swzczmxx  set xzgbxtzc=?,kpwybh=?,kph=? where id=?";
                param3[0]=gbjson.getString("code");
                param3[1]=gbjson.getString("code");
                param3[2]=gbjson.getString("kph");
                param3[3]=swjson.getString("code");
                Map<String,Object> sqlmap3=new HashMap<>();
                sqlmap3.put("sql",sql13);
                sqlmap3.put("params",param3);
                sqllist.add(sqlmap3);

                //更新  实物异常表数据
                Object[] param4=new Object[2];
                //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                String sql14="update uf_swnewexception  set sfyxz=? where swzcid=?";
                param4[0]=0;
                param4[1]=swjson.getString("code");
                Map<String,Object> sqlmap4=new HashMap<>();
                sqlmap4.put("sql",sql14);
                sqlmap4.put("params",param4);
                sqllist.add(sqlmap4);

                //更新  关保异常表数据
                Object[] param5=new Object[2];
                //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                String sql15="update uf_uf_gbxtzczmxxexc  set sfyxz=? where gbzcid=?";
                param5[0]="0";
                param5[1]=gbjson.getString("code");
                Map<String,Object> sqlmap5=new HashMap<>();
                sqlmap5.put("sql",sql15);
                sqlmap5.put("params",param5);
                sqllist.add(sqlmap5);

                //跟新 实物的 单价  为关保单价
                Object[] param6=new Object[2];
                //String sql12="update uf_swzczmxx  set kpwybh=?,kph=?,xzgbxtzc=? where id=?";
                String sql16="update uf_swzczmxx  set dj=(select top 1 dj from uf_gbxtzczmxx where kpwybs=? ) where id=?";
                param6[0]=gbjson.getString("code");
                param6[1]=swjson.getString("code");
                Map<String,Object> sqlmap6=new HashMap<>();
                sqlmap6.put("sql",sql16);
                sqlmap6.put("params",param6);
                sqllist.add(sqlmap6);

                //huangwm add 2021年9月7日23:01:21 入库匹配后写入记录表
                Uf_newxz_rkppjl uf_newxz_rkppjl = new Uf_newxz_rkppjl();
                uf_newxz_rkppjl.setCzr(user.getUID()+"");
                uf_newxz_rkppjl.setRkswzc(swjson.getString("code"));
                uf_newxz_rkppjl.setPpgbzc(gbjson.getString("code"));
                uf_newxz_rkppjl.setSwpp(swjson.getString("pp"));
                uf_newxz_rkppjl.setSwggxh(swjson.getString("ggxh"));
                uf_newxz_rkppjl.setGbpp(gbjson.getString("pp"));
                uf_newxz_rkppjl.setGbggxh(gbjson.getString("ggxh"));

                log.writeLog(uf_newxz_rkppjl.toString());
                objlist.add(uf_newxz_rkppjl);
            }
            if(sqllist.size()>0){
                GbSwExceptionBaseService GbSwExceptionBaseService=new GbSwExceptionBaseService();
                errormess=GbSwExceptionBaseService.getObjMapList(null,sqllist);
                if("".equals(errormess)){
                    log.writeLog("入库匹配数据关联已匹配上");
                }
            }
            //huangwm add 2021年9月7日23:04:13 入库匹配后写入记录表
            if(objlist.size()>0){
                Uf_newxz_rkppjlBaseService rkppjlBaseService=new Uf_newxz_rkppjlBaseService();
                String ruppjl_msg = rkppjlBaseService.getObjMapList(objlist,null);
                if(!"".equals(ruppjl_msg)){
                    log.writeLog("入库匹配写入记录失败");
                }
            }
        }catch(Exception e){
            log.writeLog("Exception "+e.getMessage());
            e.printStackTrace();
        }
        return errormess;
    }

    public static void main(String[] arg){
        System.out.println(getnotCludeStr("12,13,4,55","12,7,8,9"));
    }

    /**
     * 销账确认的  明细
     * @param params
     * @param user
     * @return
     */
    public Map<String, Object> getXzQrTableData(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String pp=(String)Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String)Util.null2String(params.get("ggxh")) ;//规格型号
            String sqr=(String)Util.null2String(params.get("sqr")) ;//申请人
            String sqrbm=(String)Util.null2String(params.get("sqrbm")) ;//申请部门
            String sqrks=(String)Util.null2String(params.get("sqrks")) ;//申情人科室
            int type=Util.getIntValue((String)params.get("type"),-1) ;//0:申请中  1：已撤销 2:已同意

            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "qex17ecc14c-9d64-4a43-81a4-7b7c6f7928571111123311";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());

            String sqlwhere =" 1=1 ";
            if(type==0){
                sqlwhere=sqlwhere+" and isnull(zt,-1) in (-1)";
            }else if(type==1){
                sqlwhere=sqlwhere+" and isnull(zt,-1) in (1)";
            }
            else if(type==2){
                sqlwhere=sqlwhere+" and isnull(zt,-1) in (0)";
            }
            if(!"".equals(pp)){

                sqlwhere=sqlwhere+" and (gbpp like '%"+pp+"%' or (swpp like '%"+pp+"%')";

            }

            if(!"".equals(ggxh)){

                sqlwhere=sqlwhere+" and (gbggxh like '%"+ggxh+"%' or (ggxh like '%"+ggxh+"%')";

            }
            if(!"".equals(sqr)){
                if(sqr.endsWith(",")){
                    sqr=sqr.substring(0,sqr.length()-1);
                }
                sqlwhere=sqlwhere+" and fqr in ("+sqr+")";
            }
            if(!"".equals(sqrbm)){
                if(sqrbm.endsWith(",")){
                    sqrbm=sqrbm.substring(0,sqrbm.length()-1);
                }
                sqlwhere=sqlwhere+" and fqrbm in ("+sqrbm+")";
            }
            if(!"".equals(sqrks)){
                if(sqrks.endsWith(",")){
                    sqrks=sqrks.substring(0,sqrks.length()-1);
                }
                sqlwhere=sqlwhere+" and fqrks in ("+sqrks+")";
            }
            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)
            DoorUtil DoorUtil=new DoorUtil();
            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
                sqlwhere=sqlwhere+" and 1=1";
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
                sqlwhere=sqlwhere+" and fqrbm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
                sqlwhere=sqlwhere+" and fqrbm in ("+user.getUserSubCompany1()+")";
            }else{
                sqlwhere=sqlwhere+" and 1!=1";
            }
            log.writeLog(sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            if(type==0||type==2){//申请中的 可以选择  数据
                table.setTableType(WeaTableType.CHECKBOX);
            }
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            //String backfields =	" id,zt,fqr,fqrbm,fqrks, kpwybs,mldm,gdzcmc,ggxh,pp,kph,zcmc,swpp,swggxh,swzcbh ";
            String backfields =	" gbzcid,id,zt,fqr,fqrbm,fqrks,gbmldm,ggxh,gbpp,gbggxh,gbkph,swpp,swggxh,swzcbh,swsbmc ";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            //String fromSql=" from (select a.id,a.zt,a.fqr,a.fqrbm,a.fqrks, b.kpwybs,b.mldm,b.gdzcmc,b.ggxh,b.pp,b.kph,c.zcmc,e.ppmc swpp,d.ggxh,c.swzcbh swggxh from  uf_xzqr a left join uf_gbxtzczmxx b on a.gbzcid=b.kpwybs left join uf_swzczmxx c on a.swzcid=c.id left join uf_swzcggxh d on c.ggxh=d.id left join uf_swzcpp e on c.pp=e.id where isnull(a.sfyx,-1) in (-1,0) ) a "	;
            String fromSql="from (select a.gbzcid, a.id,a.zt,(select lastname from hrmresource where id=a.fqr) as fqr,(select subcompanyname from Hrmsubcompany where id=a.fqrbm) as bmmc, " +
                            " (case (select supsubcomid from Hrmsubcompany where id=a.fqrbm) when 5 then '中山海关' else (select subcompanyname from Hrmsubcompany where id=a.fqrbm) end) as fqrbm, "+
                            " (select departmentname from hrmdepartment where id=a.fqrks) as fqrks,a.gbkph,a.gbmldm,a.gbzclx,a.gbpp,a.gbggxh,a.gbsybm, " +
                            " a.swzcbh,a.swsblx,a.swsbmc,e.ppmc swpp,a.swggxh,a.swsybm,d.ggxh from  uf_xzqr a left join uf_swzcggxh d  on a.swggxh=d.id left join uf_swzcpp e on a.swpp=e.id where  isnull(a.sfyx,-1) in (-1,0) ) a";
            log.writeLog(fromSql);
            table.setBackfields(backfields);

            table.setSqlform(fromSql);
            table.setSqlwhere(sqlwhere);
            //table.setSqlorderby("gbzcid");
            //table.setSqlprimarykey("gbzcid");
            //kpwybs
            table.setSqlorderby("id");
            table.setSqlprimarykey("id");
            table.setSqlisdistinct("false");
            //卡片号，目录代码，固定资产名称，品牌，规格型号，所在部门2(表里有两个所在部门，取带有数字2的那个)，对应单位，关联实物资产(这个放后面)
            table.getColumns().add(new WeaTableColumn("id").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            table.getColumns().add(new WeaTableColumn("6%", "发起人", "fqr","fqr"));
            table.getColumns().add(new WeaTableColumn("8%", "发起人部门", "fqrbm","fqrbm"));
            //table.getColumns().add(new WeaTableColumn("10%", "卡片唯一标识", "gbzcid","gbzcid"));
            table.getColumns().add(new WeaTableColumn("10%", "资产卡号", "gbkph","gbkph"));
            table.getColumns().add(new WeaTableColumn("8%", "目录代码", "gbmldm","gbmldm"));
            table.getColumns().add(new WeaTableColumn("10%", "关保品牌", "gbpp","gbpp"));
            table.getColumns().add(new WeaTableColumn("10%", "关保规格型号", "gbggxh","gbggxh"));

            table.getColumns().add(new WeaTableColumn("10%", "实物资产编号", "swzcbh","swzcbh"));
            table.getColumns().add(new WeaTableColumn("10%", "实物资产名称", "swsbmc","swsbmc"));
            //table.getColumns().add(new WeaTableColumn("5%", "单价", "dj","dj"));
            //table.getColumns().add(new WeaTableColumn("5%", "使用人", "syrlastname","syrlastname"));
            table.getColumns().add(new WeaTableColumn("10%", "实物品牌", "swpp","swpp"));
            table.getColumns().add(new WeaTableColumn("10%", "实物规格", "ggxh","ggxh"));



            //增加右侧操作选项
            //weaTableOperates.setOperate(operateList);

            //table.setOperates(weaTableOperates);
            //table.setOperates(weaTableOperates);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }

    /**
     * 开启 实物  资产权限重构
     * @param lx
     * @param val
     */
    public void restModeSW(final String lx,final String val){
        new  Thread(new Runnable() {
            @Override
            public void run() {
                RecordSet re=new RecordSet();
                String sql="";
                if("0".equals(lx)){
                    sql="select id from uf_swzczmxx where dybm='"+val+"'";
                }
                if("1".equals(lx)){
                    sql="select id from uf_swzczmxx where syks='"+val+"'";
                }
                log.writeLog("管理员授权后重构实物建模表权限--》"+sql);
                ModeRightInfo mri=new ModeRightInfo();
                //权限重构
                re.execute(sql);
                while(re.next()){
                    int dataid=Util.getIntValue(re.getString("id"),0);
                    mri.editModeDataShare(Util.getIntValue(1+"",0),BaseUtle.swmodeid,dataid);
                    log.writeLog("实物建模表权限重构,billid="+dataid+",formmodeid="+BaseUtle.swmodeid+",userid=1");
                }
                log.writeLog("管理员授权后重构实物建模表权限结束");
            }
        }).start();
    }

    /**
     * 开启 关保  资产权限重构 huangwm
     * @param lx
     * @param val
     */
    public void restModeGB(final String lx,final String val){
        new  Thread(new Runnable() {
            @Override
            public void run() {
                RecordSet re=new RecordSet();
                String sql="select * from uf_gbxtzczmxx where sybm='"+val+"'";
                log.writeLog("管理员授权后重构关保建模表权限--》"+sql);
                ModeRightInfo mri=new ModeRightInfo();
                //权限重构
                re.execute(sql);
                while(re.next()){
                    int dataid=Util.getIntValue(re.getString("id"),0);
                    mri.editModeDataShare(Util.getIntValue(1+"",0),BaseUtle.gbmodeid,dataid);
                    log.writeLog("关保建模表权限重构,billid="+dataid+",formmodeid="+BaseUtle.gbmodeid+",userid=1");
                }
                log.writeLog("管理员授权后重构关保建模表权限结束");
            }
        }).start();
    }

    /**
     * 部门管理员修改时  重构科室管理员的模块权限 huangwm
     * @param val
     */
    public void restModeKsgly(final String val){
        new  Thread(new Runnable() {
            @Override
            public void run() {
                RecordSet re=new RecordSet();
                String sql="select id from uf_ksglysq where szbm='"+val+"'";
                log.writeLog("部门管理员授权后重构科室管理员建模表权限--》"+sql);
                ModeRightInfo mri=new ModeRightInfo();
                //权限重构
                re.execute(sql);
                while(re.next()){
                    int dataid=Util.getIntValue(re.getString("id"),0);
                    mri.editModeDataShare(Util.getIntValue(1+"",0),Util.getIntValue(BaseUtle.depmodeid),dataid);
                    log.writeLog("实物科室管理员建模表权限重构,billid="+dataid+",formmodeid="+BaseUtle.depmodeid+",userid=1");
                }
                log.writeLog("部门管理员授权后重构科室管理员建模表权限结束");
            }
        }).start();
    }

}
